// pages/resumeDetail/resumeDetail.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    isService: false,
    isCollection: false,
    personInfo: {},
    content: '',
    type: null
  },

  // 查看证书
  previewImage: function (e) {
    let current = e.target.dataset.src
    let imgList = this.data.personInfo.r_args25
    wx.previewImage({
      urls: imgList,
      current
    })
  },

  // 发起雇佣
  toHire: function () {
    if (this.data.type == 'index') {
      wx.navigateTo({
        url: '/pages/recruitmentInProgress/recruitmentInProgress?resumeId=' + this.data.personInfo.r_id,
      })
    } else {  
      wx.navigateTo({
        url: '/pages/hire/hire?workId=' + this.data.personInfo.wr_work_id + '&resumeId=' + this.data.personInfo.wr_resume_id,
      })
    }
  },

  // 收藏
  collection: function () {
    app.post('Member/collectResume', {
      token: wx.getStorageSync('token'),
      resumeId: this.data.personInfo.r_member_id
    }).then(res => {
      wx.showToast({
        title: res.data.result_code == 100 ? '收藏成功' : '取消成功',
      })
      this.setData({
        isCollection: !this.data.isCollection
      })
    })
  },

  // 咨询
  service: function (e) {
    this.setData({
      isService: true
    })
  },

  // 咨询内容
  contentInput: function (e) {
    this.data.content = e.detail.value

  },

  // 咨询内容提交
  contentSubmit: function (e) {
    if (this.data.content == '') {
      wx.showToast({
        title: '请填写内容',
        icon: 'none'
      })
    } else {
      app.post('Member/send', {
        token: wx.getStorageSync('token'),
        detail: this.data.content,
        receive: this.data.personInfo.r_id,
      })
      this.setData({
        isService: false
      })
    }
  },

  // 取消
  cancel: function () {
    this.setData({
      isService: false
    })
  },


  // 禁止页面穿透
  noMove: function () {
    return false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let id = options.id
    console.log(options);

    wx.showLoading({
      title: '正在加载...',
    })
    if ('wid' in options) {
      app.post('Work/deliveryRecordDetail', {
        wrid: options.wid,
        token: wx.getStorageSync('token')
      }).then(res => {
        let personInfo = res.data.result_data
        personInfo.r_args12 = personInfo.r_args12.split(',')

        this.setData({
          personInfo,
          isCollection: personInfo.r_collect == 0 ? false : true
        })
      })
    }
    if ('rid' in options) {
      app.post('Index/resumeDetail', {
        id: options.rid,
        token: wx.getStorageSync('token')
      }).then(res => {
        let personInfo = res.data.result_data
        personInfo.r_args12 = personInfo.r_args12.split(',')

        this.setData({
          personInfo,
          isCollection: personInfo.r_collect == 0 ? false : true
        })
      })
    }
    this.setData({
      type: options.type
    })
    wx.hideLoading()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})